from openpyxl import Workbook
import json
import requests
menu_new_url = 'https://open.xiaohongshu.com/api/doc/listNew'

menu_data_url = 'https://open.xiaohongshu.com/api/doc/second/listNew?apiNavigationId=%d'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'}
response = requests.get(menu_new_url, headers=headers)

menu_new_json = response.json()
menu_new_list = menu_new_json['data']
menu_list =json.loads(menu_new_list)
wb = Workbook()
ws = wb.active
for menu in menu_list:
    menu_id = menu['id']
    menu_name = menu['navigationName']
    menu_response = requests.get(menu_data_url% menu_id, headers=headers)
    menu_data_json = menu_response.json()
    menu_data_list = menu_data_json['data']
    menu_data =json.loads(menu_data_list)
    for data in menu_data:
        desc = data['navigationDetailDesc']
        row_data = [menu_name,desc]
        ws.append(row_data)
wb.save('menu.xlsx')